#    Stingingnettlepy - A website generator for creating simple static websites.
#    Copyright (C) 2013  Jannik Haberbosch
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Standard Python modules.
import os
import os.path

# Project modules.
from stingingnettlepy.constants import constants


# The entry-point.
def main():
	"""Initialises a website project directory.
	
	"""

	# The current working directory needs be empty.
	if len( os.listdir( os.getcwd() ) ) > 0:
		# The current working directory is not empty.
		print( constants.MSG_ERR_DIR_NOT_EMPTY % os.getcwd() )
		return False
		
	# Create the required directories and files for the website project directory.
	for rpath in constants.INIT_RELPATHS:
		
		# Determine whether to create a file or a directory.
		if rpath.endswith( constants.FILE_ENDINGS ):
			# Create a file.
			try:
				with open( rpath, "w" ) as f:
					f.close()
			except IOError as e:
				print( e.strerror )
		else:
			# Create a directory.
			try:
				os.makedirs( rpath )
			except IOError as e:
				print( e.strerror )

	return True
